import Vue from 'vue'
import Router from 'vue-router'
import { MessageBox } from 'element-ui';

Vue.use(Router)
const router =new  Router({
    routes: [
        {
            path: '/',
            redirect: '/index'
        },
        {
            path: '/',
            name: 'index',
            meta: {
                title: '欢迎光临'
            },
            component: resolve => require(['@/views/index'], resolve),
        },],

})
router.beforeEach((to, from, next) => {

    if (to.meta.title) {
        document.title = to.meta.title
    }
    if (localStorage.getItem('tokenData')){
        next();
    }else {
        try {
            if(to.path=="要去的路径"){
                MessageBox.confirm('是否现在去登录?', '您还未登录', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    next()
                }).catch(() => {
                    if (to.path=="打开窗口"){
                        window.close();
                    }else {
                        next()
                    }
                });
            }else {
                next();

            }
        } catch (err){
            console.log('您还未登录')
        }

    }


    scroll(0,0)
})
export default router
